/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Graphics;

import ClientGraphics.GraphicsMain;
import GameEngine.GameConstants.Graphic;
import GameEngine.Vector;
import Objects.BasicObject;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.Random;
import java.util.TimerTask;

/**
 *
 * @author ag12
 */
public class AnimationTask implements ActionListener
{
    ArrayList<BasicObject> basic;
    GraphicsMain g;
    int neg;
    public AnimationTask(GraphicsMain g) {
        basic = new ArrayList<BasicObject>();
        basic.add(new BasicObject(new Vector(1,0), new Vector(125,62),
                new Vector(75,75),Graphic.PINKPLAYER_WALK));
        System.out.println(basic.get(0));
        this.g=g;
        neg=1;
    }

    @Override
    public void actionPerformed(ActionEvent e)
    {
        BasicObject o = basic.get(0);
         o.getCenter().add(neg*5,0);
        if(o.getCenter().getX()>220)
        {
            neg = -1;
            o.setGraph(Graphic.PINKPLAYER_WALKLEFT);
        }
        if(o.getCenter().getX()<30)
        {
            neg = 1;
            o.setGraph(Graphic.PINKPLAYER_WALK);
        }
        Random r = new Random();
        int rand = r.nextInt(30);
        if(rand== 2)
        {
            neg = neg*-1;
            if(o.getGraph() == Graphic.PINKPLAYER_WALK)
                o.setGraph(Graphic.PINKPLAYER_WALKLEFT);
            else
                o.setGraph(Graphic.PINKPLAYER_WALK);
        }
        g.update(basic);
    }

    }
